package manage.service.impl;

import manage.config.Cons;
import manage.dao.UserDao;
import manage.domain.User;
import manage.service.UserService;
import manage.util.Pager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;



    @Autowired
    private Cons cons;

    @Override
    public boolean append(User user, MultipartFile file) {





            return this.userDao.insert(user);

    }
    @Override
    public boolean remove(Integer id) {





        return this.userDao.delete(id);
    }
    @Override
    public boolean disabled(User user) {


        return this.userDao.update(user);
    }
    @Override
    public User detail(Integer id) {
        return this.userDao.selectById(id);
    }


    @Override
    public User login(String username, String password, HttpServletRequest request) {

        User user=this.userDao.selectByUsernameAndPassword(username,password);



        return user;
    }

    @Override
    public Pager<User> list(User condition, Integer page) {

        int pageSize = this.cons.getPage_size();

        List<User> datas = this.userDao.selectsByCondition(condition,  (page - 1) * pageSize, pageSize);
        int size = this.userDao.sizeByCondition(condition);

        return new Pager<User>(datas, size, page, pageSize);
    }
    @Override
    public boolean isExistByUserName(String username) {
        return this.userDao.isExistByUserName(username) > 0 ? true : false;
    }
}
